package com.leetcode.LC;

public class LC496 {

    public int[] nextGreaterElement(int[] nums1, int[] nums2) {

        int[] ints = new int[nums1.length];
        boolean f = false;
        int k = -1;
        for (int i : nums1) {
            f = false;
            for (int j : nums2) {
                if (i < j) {
                    k++;
                    ints[k] = j;
                    f = true;
                    break;
                }
            }
            if (!f) {
                k++;
                ints[k] = -1;
            }
        }
        return ints;

    }

    public int[] nextGreaterElement2(int[] nums1, int[] nums2) {

        int[] ints = new int[nums1.length];
        boolean f;
        int k = -1, a;
        for (int i : nums1) {
            a = k;
            f = false;
            for (int j : nums2) {
                if (f == false && j != i) {
                    continue;
                } else if (f == false && j == i) {
                    f = true;
                    continue;
                }
                if (f && i < j) {
                    k++;
                    ints[k] = j;
                    break;
                }
            }
            if (a == k) {
                k++;
                ints[k] = -1;
            }


        }
        return ints;

    }

    public static void main(String[] args) {
        for (int i : new LC496().nextGreaterElement2(new int[]{4, 1, 2}, new int[]{1, 3, 4, 2})) {
            System.out.print(i + ",");
        }
    }

}
